<template>
  <div v-if="sureAdmin">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>当前位置：充值记录</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="6" :offset="17">
          <el-input
            placeholder="搜索用户名"
            v-model="query"
            clearable
            @clear="getRecharge"
            type="primary"
          >
            <el-button
              class="button"
              slot="append"
              icon="el-icon-search"
              @click="getRechargeName(1)"
            ></el-button
          ></el-input>
        </el-col>
      </el-row>
      <!-- 用户列表区域 -->
      <el-table :data="userRechargeList" border stripe>
        <!-- <el-table-column type="index"></el-table-column> -->
        <el-table-column
          label="充值单号"
          prop="number"
          sortable
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="用户名称"
          prop="userName"
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="充值金额"
          prop="usageRecord"
          sortable
          min-width="10%"
        ></el-table-column>
        <el-table-column
          label="充值时间"
          prop="time"
          sortable
          min-width="10%"
        ></el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 获取用户列表的参数对象
      queryInfo: {
        // 当前的页数
        pageNo: 1,
        // 当前每页显示多少条数据
        pageSize: 10,
        userId:0
      },
      query:"",
      userRechargeList: [],
      total: 0,
      sureAdmin: false,
    };
  },
  created() {
    var Admin = window.localStorage.getItem("admin");
    if (Admin == 1) {
      this.getRecharge();
      this.sureAdmin = true;
      // this.getUserList();
    } else {
      this.sureAdmin = false;
    }
  },
  methods: {
    async getRecharge() {
      const { data: res } = await this.$http.get("wallet/listDetailed",{
        params: this.queryInfo,
      });
      console.log(res);
      if (res.code !== 200) {
        return this.$message.error("获取充值列表失败！");
      }
      this.userRechargeList = res.data.listDetailedVOs;
      this.total = res.data.count;
    },
    async getRechargeName(pageNo){
      this.queryInfo.pageNo = pageNo;
      const { data: res } = await this.$http.get("wallet/listDetailedLikeName?keyWord="+this.query,{
        params: this.queryInfo,
      });
      console.log(res);
      if (res.code !== 200) {
        return this.$message.error("获取充值列表失败！");
      }
      this.userRechargeList = res.data.listDetailedVOs;
      this.total = res.data.count;
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pageSize = newSize;
      if(this.query == ""){
        return this.getRecharge();
      }
      this.getRechargeName(this.queryInfo.pageNo);
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      console.log(newPage);
      this.queryInfo.pageNo = newPage;
      if(this.query==""){
        return this.getRecharge();
      }
      this.getRechargeName(this.queryInfo.pageNo);
    },
  },
};
</script>

<style lang="less" scoped>
.button:hover {
  background-color: rgb(64, 158, 255);
  color: rgb(255, 255, 255);
}
</style>
